minimum

您所在的位置:网站首页 kruskal python minimum

minimum

2024-05-11 03:30| 来源: 网络整理| 查看: 265

Returns a minimum spanning tree or forest on an undirected graph G.

Parameters: Gundirected graph

An undirected graph. If G is connected, then the algorithm finds a spanning tree. Otherwise, a spanning forest is found.

weightstr

Data key to use for edge weights.

algorithmstring

The algorithm to use when finding a minimum spanning tree. Valid choices are ‘kruskal’, ‘prim’, or ‘boruvka’. The default is ‘kruskal’.

ignore_nanbool (default: False)

If a NaN is found as an edge weight normally an exception is raised. If ignore_nan is True then that edge is ignored instead.

Returns: GNetworkX Graph

A minimum spanning tree or forest.

Notes

For Borůvka’s algorithm, each edge must have a weight attribute, and each edge weight must be distinct.

For the other algorithms, if the graph edges do not have a weight attribute a default weight of 1 will be used.

There may be more than one tree with the same minimum or maximum weight. See networkx.tree.recognition for more detailed definitions.

Isolated nodes with self-loops are in the tree as edgeless isolated nodes.

Examples

>>> G = nx.cycle_graph(4) >>> G.add_edge(0, 3, weight=2) >>> T = nx.minimum_spanning_tree(G) >>> sorted(T.edges(data=True)) [(0, 1, {}), (1, 2, {}), (2, 3, {})]


【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3